package com.tosee.model.dbTosee;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * Classe représentant une série.
 * 
 * @author robint
 */
@Entity
@Table(name = "T_USER_USR")
public class User {

    /**
     * Identifiant.
     */
    @Id
    @Column(name = "USR_ID", nullable = false, unique = true)
    @GeneratedValue
    private int id;

    /**
     * Login
     */
    @Column(name = "USR_LOGIN", nullable = false, unique = true)
    private String login;

    /**
     * Email
     */
    @Column(name = "USR_EMAIL", nullable = false, unique = true)
    private String email;

    /**
     * Mot de passe
     */
    @Column(name = "USR_MDP", nullable = false, unique = true)
    private String mdp;

    /**
     * Grain de sel
     */
    @Column(name = "USR_GRAIN_SEL", nullable = false, unique = true)
    private String grainSel;

    /**
     * Date de création du compte
     */
    @Column(name = "USR_DATE_CREATE", nullable = false, unique = true)
    private Date dateCreation;

    /**
     * Date de derniere action
     */
    @Column(name = "USR_LAST_ACTION", nullable = false, unique = true)
    private Date dateLastAction;

    /**
     * Liste des séries
     */
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "T_USER_SERIE_USS", joinColumns = { @JoinColumn(name = "USR_ID") }, inverseJoinColumns = { @JoinColumn(name = "SRE_ID") })
    private Set<Serie> listeSerie;

    /**
     * Liste des episodes
     */
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "T_USER_EPISODE_USE", joinColumns = { @JoinColumn(name = "USR_ID") }, inverseJoinColumns = { @JoinColumn(name = "EPE_ID") })
    private Set<Episode> listeEpisode;

    /***
     * Constructeur par défaut.
     */
    public User() {
        super();
    }

    /**
     * Constructeur.
     * 
     * @param revendeur revendeur
     * @param codeClient codeClient
     * @param compagnieId compagnieId
     * @param clientDroits clientDroits
     */
    public User(int _id) {
        super();
        this.id = _id;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (id ^ (id >>> 32));
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        }
        if(obj == null) {
            return false;
        }
        if(getClass() != obj.getClass()) {
            return false;
        }
        User other = (User) obj;
        if(id != other.id) {
            return false;
        }
        return true;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the login
     */
    public String getLogin() {
        return login;
    }

    /**
     * @param login the login to set
     */
    public void setLogin(String login) {
        this.login = login;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the mdp
     */
    public String getMdp() {
        return mdp;
    }

    /**
     * @param mdp the mdp to set
     */
    public void setMdp(String mdp) {
        this.mdp = mdp;
    }

    /**
     * @return the grainSel
     */
    public String getGrainSel() {
        return grainSel;
    }

    /**
     * @param grainSel the grainSel to set
     */
    public void setGrainSel(String grainSel) {
        this.grainSel = grainSel;
    }

    /**
     * @return the dateCreation
     */
    public Date getDateCreation() {
        return dateCreation;
    }

    /**
     * @param dateCreation the dateCreation to set
     */
    public void setDateCreation(Date dateCreation) {
        this.dateCreation = dateCreation;
    }

    /**
     * @return the dateLastAction
     */
    public Date getDateLastAction() {
        return dateLastAction;
    }

    /**
     * @param dateLastAction the dateLastAction to set
     */
    public void setDateLastAction(Date dateLastAction) {
        this.dateLastAction = dateLastAction;
    }

    /**
     * @return the listeSerie
     */
    public Set<Serie> getListeSerie() {
        return listeSerie;
    }

    /**
     * @param listeSerie the listeSerie to set
     */
    public void setListeSerie(Set<Serie> listeSerie) {
        this.listeSerie = listeSerie;
    }

    /**
     * @return the listeEpisode
     */
    public Set<Episode> getListeEpisode() {
        return listeEpisode;
    }

    /**
     * @param listeEpisode the listeEpisode to set
     */
    public void setListeEpisode(Set<Episode> listeEpisode) {
        this.listeEpisode = listeEpisode;
    }

}
